package com.corpdata.app.project.controller;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestParam;

import com.corpdata.app.contract.service.ContractInfoService;
import com.corpdata.app.project.entity.ProjectPartition;
import com.corpdata.app.project.service.ProjectPartitionService;
import com.corpdata.common.domain.DataGridRequestDTO;
import com.corpdata.common.result.Result;
import com.corpdata.common.utils.DateUtils;
import com.corpdata.system.log.OptLog;
import com.corpdata.system.log.OptLogConstant;
import com.corpdata.system.log.WebLog;
import com.corpdata.core.base.BaseController;

/**
 * 楼层分区
 * 
 * @author wu
 * @email 64088839@qq.com
 * @date 2018-06-08 15:23:00
 */
 
@Controller
@RequestMapping("app/projectPartition")
public class ProjectPartitionController extends BaseController{

	@Autowired
	private ProjectPartitionService projectPartitionService;
	
	@Autowired
	private ContractInfoService ciServ;
	
	//新增页面
	@GetMapping("/add")
	public String add(){
		return "app/project/partition/partition_add";
	}
	
	//保存数据
	@WebLog()
	@ResponseBody
	@RequestMapping("/save")
	@OptLog(info=OptLogConstant.INFO_ADD+"分区",module="分区")
	public Result save(ProjectPartition record,String stationNames){
		return projectPartitionService.insert(record,stationNames);
	}
	
	//编辑页面
	@RequestMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id,ModelMap map){
		map.put("record", projectPartitionService.findById(id));
		return "app/project/partition/partition_edit";
	}
	
	//更新数据
	@WebLog()
	@ResponseBody
	@RequestMapping("/update")
	@OptLog(info="修改分区",module="分区")
	public Result update(ProjectPartition record){
		return projectPartitionService.update(record);
	}
	
	//删除
	@WebLog()
	@ResponseBody
	@PostMapping("/delete")
	@OptLog(info="删除分区",module="分区")
	public Result delete(String id){
		return projectPartitionService.deleteById(id);
	}
	
	//批量删除
	@WebLog()
	@ResponseBody
	@PostMapping("/deletes")
	public Result deletes(@RequestParam("ids[]") String[] ids){
		return projectPartitionService.deleteByIds(ids);
	}
	
	//详情页面
	@GetMapping("/details/{id}")
	public String details(ModelMap map,@PathVariable("id") String id){
		map.put("record", projectPartitionService.findById(id));
	    return "app/project/projectPartition_details";
	}
	
	//列表页面
	@GetMapping("/list")
	public String list(){
	    return "app/project/projectPartition_list";
	}
	
	//列表数据
	@ResponseBody
	@RequestMapping("/listdata")
	public String findByPage(DataGridRequestDTO dgRequest){
		//获取有续签的合同id
		/*List<String> idList = ciServ.getReNewIdList();
		if(idList.size()>0){
			dgRequest.getParams().put("idList", idList);
			dgRequest.setParams(dgRequest.getParams());
		}*/
		return projectPartitionService.findByPage(dgRequest);
	}
	
	//列表数据
	@ResponseBody
	@RequestMapping("/selPartition")
	public String selPartition(String id){
		return projectPartitionService.selPartition(id);
	}
	
	//列表页面
	@GetMapping("/radio")
	public String radio(){
	    return "app/project/partition/partition_radio";
	}
	//单项选择页面
	@GetMapping("/radio/{type}_{id}_{date}_{fengbiIds}_{projectId}")
	public String radio(ModelMap map,@PathVariable("type") String type,@PathVariable("id") String id,@PathVariable("date") String date,@PathVariable("fengbiIds") String fengbiIds,@PathVariable("projectId") String projectId){
		map.put("type",type);
		map.put("id",id);
		map.put("fengbiIds", fengbiIds);
		map.put("projectId", projectId);
		//如果日期为空，设置日期为今天
		if(StringUtils.isBlank(date)){
			date = DateUtils.format(new Date());
		}
		map.put("date", date);
	    return "app/project/partition/partition_radio";
	}
	
}
